DESTDIR ?= /kf/nfs/tmp/app/

ifeq ($(TARCH),arm)
KDIR = /kf/kernel/kernel_4418/kernel-3.4.39
else
KDIR = /lib/modules/$(shell uname -r)/build
endif

ifeq ($(TARCH),arm)
CROSS_COMPILE = arm-cortex_a9-linux-gnueabi-
endif

CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++

obj-m += logman.o

logman-objs += logman_main.o
logman-objs += logman_file.o
logman-objs += logman_workqueue.o
logman-objs += logman_fifo.o
logman-objs += logman_timer.o

all: build app socket
ifneq ($(DESTDIR),)
	cp -raf *.ko app socket $(DESTDIR)
endif

build: 
ifeq ($(CROSS_COMPILE),)
	make -C $(KDIR) M=$(PWD) modules
else
	make -C $(KDIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules
endif

app: app.o
	$(CPP) -Wall -o $@ $<

socket: socket.o
	$(CPP) -Wall -o $@ $<

%.o: %.cpp
	$(CPP) -Wall -c -o $@ $<

clean:
	make -C $(KDIR) M=$(PWD) clean
	
	rm -rf *.o *.ko app socket
